// packageA/pages/userList/userList.js
const app = getApp();
import CommonService from '../../../utils/service/commonService.js';
import Toast from '../../../miniprogram_npm/@vant/weapp/toast/toast';

Page({

  /**
   * 页面的初始数据
   */
  data: {
    //列表
    list: [],
    //页码
    page: 1,
    //是否无更多
    notMore: true,
    //无数据
    showNothing: false,
    //项目选择框
    showProject: false,
    //项目选择数据
    projectList: [],
    //项目id
    projectId: null,
    //项目名称
    projectName: '选择项目',
    //搜索关键词
    searchValue: '',
    //权限
    authority: null,

    editTaskPlanObj: {},
    // 当前展开项的ID（初始不展开任何项）   
    activeName: null,
    //任务列表
    taskList: [],
    //显示任务详情
    addTaskShow: false,
    //任务内容
    editTaskObj: {},
    //项目列表
    departList: [],
    //选择项目
    projectShow: false,
    //已选择项目列表
    listProjectMap: {},
    //点击单元行，任务信息默认禁用
    isDisable: true,
    disabled: false,
    dayData: {},
    itemArr: [],
    // 动态频次列表：每个对象对应一个频次条目，周频次
    frequencyList: [],
    //动态频次列表，每个对象对应一个频次条目,月频次
    frequencyMonthList: [],
    createTaskListShow: false,
    showUpdateFrequency: false,
    showUpdateFrequencyOfWeek: false,
    minDate: '',
    maxDate: '',
    days: [],
    weeks: [],
    freNum: 1,
    showTaskItemWin: false,
    taskItem: '',
    taskItemIndex: [],
    showProjects: false,
    checkedAllProjectInTaskVal: false,
    checkedProjectInTaskVal: [],
    testProList: [],
    editWeekInfo:{},
    updateIndex:[],
    updateTag:"weekly",
    showCreateTaskListDialog:false,
    createTaskListData:{},
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      authority: app.globalData.authority
    })

    if (options.paramObj) {
      let paramObj = JSON.parse(options.paramObj);
      this.setData({
        paramObj: paramObj
      })
    }

    //获取列表数据
    // this.getList();
    //获取任务计划列表
    this.getPlanList();
    let now = new Date();
    this.setData({
      minDate: new Date(now.getFullYear, now.getMonth, 1).getTime(),
      maxDate: new Date(now.getFullYear, now.getMonth, 0).getTime(),
    });

    this.setDateNumber();
    this.setWeek();

    // 删除代码
    var tp = []
    for (let i = 1; i < 30; i++) {
      tp.push({
        id: i,
        name: "项目" + i,
        checked: false,
      });
    }
    this.setData({
      testProList: tp
    });
  },

  setDateNumber() {
    let days = []
    for (let i = 1; i <= 31; i++) {
      days.push({
        date: i,
        number: i + "号",
        checked: false,
      });
    }
    this.setData({
      days: days
    });
  },


  setWeek(weekSelected) {
    let week = ["周一", "周二", "周三", "周四", "周五", "周六", "周日"]
    let weeks = []
    for (let i = 1; i <= 7; i++) {
      let flg = false;
      if (weekSelected != null && weekSelected.get(i)) {
        flg = true
      }
      weeks.push({
        date: i,
        week: week[i - 1],
        checked: flg,
      });
    }
    this.setData({
      weeks: weeks
    });
  },

  editFunc() {
    this.setData({
      isDisable: false
    })
  },

  //选择任务类型
  onchangetype(event) {
    let taskType = 'editTaskObj.taskType';
    this.setData({
      [taskType]: event.detail,
    })
  },
  healthDetail(e) {
    //跳转健康详情页面
    let data = {
      imei: e.currentTarget.dataset.detail.imei,
      dataType: e.currentTarget.dataset.type
    }
    // wx.navigateTo({
    //   url: "/packageA/pages/healthDetail/healthDetail"
    // })
    wx.navigateTo({
      url: '/packageA/pages/healthDetail/healthDetail?paramObj=' + JSON.stringify(data)
    })
  },

  //获取输入的数量
  onChangePartNum(event) {
    let names = 'editTaskObj.taskObj.imgCountRequire'
    this.setData({
      [names]: event.detail
    })
  },

  onChangFrequency(e){
      let editTag = this.data.updateTag;
      let editIndex = this.data.updateIndex;
      if (editTag == "weekly"){
        this.setData({
          [`itemArr[${editIndex[0]}].frequencyList[${editIndex[1]}].frequency`]: e.detail
        })
      }else if(editTag == "monthly"){
        this.setData({
          [`itemArr[${editIndex[0]}].frequencyMonthList[${editIndex[1]}].frequency`]: e.detail
        })
      }

  },

  getPlanList() {
    Toast.loading({
      duration: 0,
      forbidClick: true,
      message: '加载中...'
    });
    let param = {
      searchAll: true,
      className: 'inspectionTaskPlan',
      data: {
        selectFields: ['id', 'dayData', 'frequencyList', 'frequencyMonthList', 'state'],
      }
    }

    CommonService.goFindList(param).then(res => {
      Toast.clear();
      if (res.data.data && res.data.data.result && res.data.data.result.length) {
        let result = res.data.data.result;
        let saveArr = [
          ...result.map(item => ({
            ...item,
            activeName: "",
            showDaily: false,
            showWeekly: false,
            showMonthly: false,
            dailyHeight: '0',
            weeklyHeight: '0',
            monthlyHeight: '0'
          })),
        ];
        this.setData({
          itemArr: saveArr
        })
      }
    }).catch((error) => {
      Toast.clear();
    })
  },

  //点击“生成清单”按钮，弹出确认框
  createTaskListDialog(e){
    let id = e.currentTarget.dataset.detail.id;
    let state = e.currentTarget.dataset.detail.state
    console.log(e);
    let param = {
      className: 'inspectionTaskPlan',
      data: {
        id: id,
        state: 1
      }
    }
    if (state == 1){
      this.setData({
        createTaskListData:param,
        showCreateTaskListDialog : true
      })
    }else{
      this.setData({
        createTaskListData:param,
        showCreateTaskListDialog : false
      })
      this.createTaskList(-1);
    }
      
  },
  //同步生成清单并删除已存在处理的任务
  createTaskListAndDelete(){
    this.createTaskList(1);
  },
  //同步生成清单并不删除已存在处理的任务
  createTaskListAndUnDelete(){
    this.createTaskList(0);
  },

  //生成清单,sign  1:同步生成清单并删除已存在处理的任务  0：同步生成清单并不删除已存在处理的任务   -1：第一次生成清单
  createTaskList(sign) {
    const {createTaskListData} = this.data;
    CommonService.goSave(createTaskListData).then(res => {
      if (res.statusCode == 200 && res.data.success == true) {
        //如果有集体任务，直接保存到任务清单
        this.createTaskListFunc(createTaskListData.data.id,sign);
        this.getPlanList();
      } else if (res.statusCode == 202) {
        Toast.fail('您操作太快了,请勿重复提交');
      } else {
        Toast.fail('操作失败');
      }
    }).catch((error) => {
      Toast.fail('操作失败');
    })
  },


  //生成清单
  // createTaskList(e) {
  //   console.log(e);
  //   this.setData({
  //     createTaskListShow: true
  //   })
  //   let id = e.currentTarget.dataset.detail.id
  //   let param = {
  //     className: 'inspectionTaskPlan',
  //     data: {
  //       id: id,
  //       state: 1
  //     }
  //   }
  //   CommonService.goSave(param).then(res => {
  //     this.setData({
  //       createTaskListShow: false
  //     })
  //     if (res.statusCode == 200 && res.data.success == true) {
  //       //如果有集体任务，直接保存到任务清单
  //       this.createTaskListFunc(id);
  //       this.getPlanList();
  //     } else if (res.statusCode == 202) {
  //       Toast.fail('您操作太快了,请勿重复提交');
  //     } else {
  //       Toast.fail('操作失败');
  //     }
  //   }).catch((error) => {
  //     Toast.fail('操作失败');
  //   })

  // },

  //生成任务清单
  createTaskListFunc(id,sign) {
    let data = {
      id: id,
      sign:sign
    }
    CommonService.createTaskListHand(data).then(res => {

    })
  },
  //修改
  updateTaskPlanNew(e){
    let paramObj={};
    if(e.currentTarget.dataset.detail){
      let detail=e.currentTarget.dataset.detail;
      paramObj=detail
    }
    wx.navigateTo({
      url: "/packageB/pages/taskPlanAdd/taskPlanAdd?paramObj="+JSON.stringify(paramObj)
    })
  },

  //修改计划
  updateTaskPlan(e) {
    let td = e.currentTarget.dataset.detail;
    let saveArr = [];
    let frequencyList = td.frequencyList;
    let frequencyMonthList = td.frequencyMonthList;
    // 为每个数组的元素添加 type 字段，并合并到新数组
    saveArr = [
        ...frequencyList.map(item => ({
            ...item,
        })),
        ...frequencyMonthList.map(item => ({
            ...item,
        }))
    ];
    let dayData = td.dayData;
    saveArr.push(dayData);
    const checkIds = saveArr.flatMap(item => item.dayTaskIdArr);
    let param = {
        className: 'inspectionTaskPlan',
        data: {
            id: td.id,
            dayData: dayData,
            frequencyList: frequencyList,
            frequencyMonthList: frequencyMonthList,
            taskArrId: checkIds,
        }
    }

    const union = [...new Set([...checkIds, ...this.data.taskAll])];
    // 计算差集（A - B，即只在A中出现的元素）
    const difference = this.data.taskAll.filter(
        item => !checkIds.includes(item)
    );
    console.log("----------------------------------------");
    //避免表单重复提交
    Toast.loading({
        duration: 0,
        forbidClick: true,
        message: '数据提交中...'
    });
    CommonService.goSave(param).then(res => {
        this.setData({
            disabled: false
        })
        if (res.statusCode == 200 && res.data.success == true) {
            Toast.success('操作成功');
            //更新任务列表标记，已经选择的任务，下次不能再继续建
            if (union.length > 0) {
                this.updateTaskRecordSgin(union, true)
            }
            if (difference.length > 0) {
                this.updateTaskRecordSgin(difference, false)
            }
            setTimeout(() => {
                //返回列表页并刷新数据
                this.backAndRefresh();
            }, 1000);
        } else if (res.statusCode == 202) {
            Toast.fail('您操作太快了,请勿重复提交');
        } else {
            Toast.fail('操作失败');
        }
    }).catch((error) => {
        Toast.fail('操作失败');
    })
  },


  //选择项目事件
  onChangeProjectCheck({
    currentTarget
  }) {
    let detail = currentTarget.dataset.detail;
    let list = this.data.departList;
    let listMap = this.data.listProjectMap;
    list.forEach(item => {
      if (item.id == detail.id) {
        //点击复选框时切换选中
        item.checked = !item.checked;
        if (item.checked) {
          //选中的放入已选列表，利用map避免重复
          listMap.set(item.id, item);
        } else {
          //未选中的从map中删除
          listMap.delete(item.id);
        }
      }
    });

    //列表是否全被选中了
    let flag = list.every(item => {
      return item.checked;
    });

    //是否选中全选
    if (flag) {
      this.setData({
        checkedAll: true
      })
    } else {
      this.setData({
        checkedAll: false
      })
    }
    this.setData({
      departList: list,
      listProjectMap: listMap
    })
  },

  //隐藏部门
  onCloseDepart() {
    this.setData({
      projectShow: false,
    })
  },

  //选择完项目确定事件
  onConfirmUser() {
    let listMap = this.data.listProjectMap;
    //map转成数组
    let arr = [...listMap.values()];

    //名字
    let names = [];
    let projectIds = [];
    arr.forEach(item => {
      names.push(item.name);
      projectIds.push(item.id);
    });

    let projectArr = 'editTaskObj.projectArr';
    let projectName = 'editInfo.projectName';
    let projectId = 'editTaskObj.projectIds';
    this.setData({
      [projectArr]: arr,
      [projectName]: names,
      [projectId]: projectIds
    })

    this.onCloseDepart();
  },

  //显示部门
  onShowDepart() {
    if (!this.data.isDisable) {
      this.setData({
        projectShow: true
      })
      this.getDepartList();
    }

  },

  onConfirmTask() {
    this.setData({
      disabled: true
    })
    const {
      editTaskObj
    } = this.data
    editTaskObj.taskType = parseInt(editTaskObj.taskType)
    let data = {
      className: 'taskReocrd',
      data: editTaskObj
    }
    CommonService.goSave(data).then(res => {
      if (res.statusCode == 200 && res.data.success == true) {
        this.setData({
          disabled: false
        })
        Toast.success('成功');
        this.setData({
          addTaskShow: false,
          isDisable: true,
        })
        setTimeout(() => {
          //返回列表页并刷新数据
          this.getPlanList();
        }, 1000);
      } else if (res.statusCode == 202) {
        Toast.fail('您操作太快了,请勿重复提交');
      } else {

        Toast.fail('操作失败');
      }
    }).catch((error) => {
      Toast.fail('操作失败');
    })
  },

  //查询部门
  getDepartList() {
    this.setData({
      departList: []
    })

    let param = {
      isAuth: false,
      className: 'depart',
      data: {
        searchAll: true,
        isProject: true,
        selectFields: ['id', 'name', 'regionId', 'region', 'fid', 'fDepart', 'companyId', 'company', 'area', 'type']
      }
    }
    CommonService.goFindList(param).then(res => {
      if (res.data.data && res.data.data.result && res.data.data.result.length) {
        let result = res.data.data.result;
        let arr = [];
        result.forEach(item => {
          arr.push({
            name: item.name,
            id: item.id,
            obj: item
          });
        });
        let map = new Map();
        const {
          editTaskObj
        } = this.data
        editTaskObj.projectArr.forEach(item2 => {
          map.set(item2.id, item2);
        });
        let projectList = arr;
        projectList.forEach(item => {
          if (map.get(item.id)) {
            item.checked = true;
          }
        });
        this.setData({
          listProjectMap: map,
          departList: arr
        })
      }
    }).catch((error) => {})
  },

  //关闭任务弹出层
  onCloseTaskPopup() {
    this.setData({
      addTaskShow: false,
    })
  },
  // 折叠项切换事件
  onCollapseChange(event) {
    // 获取当前点击的索引和展开的面板名称
    const {
      index: itemIndex
    } = event.currentTarget.dataset;
    // const activeName = event.detail;
    // 复制原数组
    const newItemArr = [...this.data.itemArr];
    // 更新对应itemMain的activeName
    newItemArr[itemIndex].activeName = event.detail;
    // 重新设置数据
    this.setData({
      itemArr: newItemArr
    });
  },

  onTaskClick(event) {
    this.setData({
      addTaskShow: true,
      editTaskPlanObj: event.currentTarget.dataset.taskId
    })
  },

  clearMessage(e) {
    let field = e.target.dataset.message;
    let obj = {};
    obj[field] = "";
    obj['disabled'] = false;
    this.setData(obj);
    const value = e.detail;
    let names = 'editTaskObj.taskObj.' + field
    // 更新 initTaskObj.name
    this.setData({
      [names]: value
    });
  },


  //刷新列表和页码
  refreshListAndPage() {
    this.setData({
      list: [],
      page: 1,
      notMore: true,
      showNothing: false
    })
    this.getPlanList();
  },

  //显示项目
  onShowProject() {
    this.setData({
      showProject: true
    })
    this.getProjectList();
  },

  //查询项目
  getProjectList() {
    this.setData({
      projectList: []
    })

    let param = {
      isAuth: true,
      className: 'depart',
      data: {
        searchAll: true,
        selectFields: ['id', 'name']
      }
    }

    //模糊查询
    if (this.data.valueSearchProject) {
      param.data.name = '%' + this.data.valueSearchProject + '%';
    }

    CommonService.goFindList(param).then(res => {
      if (res.data.data && res.data.data.result && res.data.data.result.length) {
        let result = res.data.data.result;
        let arr = [];

        result.forEach(item => {
          arr.push({
            text: item.name,
            id: item.id
          });
        });

        this.setData({
          projectList: arr
        })
      }
    }).catch((error) => {})
  },

  //隐藏项目
  onCloseProject() {
    this.setData({
      showProject: false,
      valueSearchProject: ''
    })
  },

  //确认项目
  onConfirmProject(e) {
    this.setData({
      projectId: e.detail.value.id,
      projectName: e.detail.value.text
    })
    this.onCloseProject();
    this.refreshListAndPage();
  },

  //搜索项目
  onChangeProjectVal(e) {
    this.setData({
      valueSearchProject: e.detail
    })
    this.getProjectList();
  },

  //获取搜索词
  onChangeSearch(e) {
    this.setData({
      searchValue: e.detail.value,
    })
  },

  //点击搜索
  onSearch() {
    this.refreshListAndPage();
  },

  //跳转任务计划
  goToSetPlan(e) {
    let paramObj = {};
    if (e.currentTarget.dataset.detail) {
      let detail = e.currentTarget.dataset.detail;
      paramObj.id = detail.id;
    }
    wx.navigateTo({
      url: "/packageB/pages/taskPlanAdd/taskPlanAdd?paramObj=" + JSON.stringify(paramObj)
    })
  },

  //显示删除确认框
  onDelete(e) {
    let detail = e.currentTarget.dataset.detail;
    this.setData({
      showDelete: true,
      deleteId: detail.id,
      deleteImei: detail.imei
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    if (this.data.notMore) {
      this.setData({
        page: this.data.page + 1
      })
      // this.getPlanList();
    }
  },

  /**
   * 获取元素高度，用于动态修改高度
   * @param {Element ID} id - 页面元素绑定的id属性
   * @author Man Yang
   * @date 07/28/2025
   */
  getElementHeight(id) {
    return new Promise(resolve => {
      wx.createSelectorQuery()
        .select(id)
        .boundingClientRect(resolve)
        .exec()
    })
  },

  /**
   * 显示巡检任务
   * @param {event} event - 点击事件
   * @author Man Yang
   * @date 07/28/2025 
   */
  async showTask(event) {
    let tag = event.target.dataset.tag;
    let index = event.target.dataset.index;
    let boxId = event.target.dataset.boxid

    let rect = await this.getElementHeight("#" + boxId)

    switch (tag) {
      case "daily":
        this.setData({
          [`itemArr[${index}].showDaily`]: !this.data.itemArr[index].showDaily,
          [`itemArr[${index}].showWeekly`]: false,
          [`itemArr[${index}].showMonthly`]: false,
          [`itemArr[${index}].dailyHeight`]: !this.data.itemArr[index].showDaily ? rect.height + 'px' : '0px',
          [`itemArr[${index}].weeklyHeight`]: '0px',
          [`itemArr[${index}].monthlyHeight`]: '0px',
        });
        break;
      case "weekly":
        console.log("rect.height:", rect.height);
        this.setData({
          [`itemArr[${index}].showDaily`]: false,
          [`itemArr[${index}].showWeekly`]: !this.data.itemArr[index].showWeekly,
          [`itemArr[${index}].showMonthly`]: false,
          [`itemArr[${index}].dailyHeight`]: '0px',
          [`itemArr[${index}].weeklyHeight`]: !this.data.itemArr[index].showWeekly ? rect.height + 'px' : '0px',
          [`itemArr[${index}].monthlyHeight`]: '0px',
        });
        break;
      case "monthly":
        this.setData({
          [`itemArr[${index}].showDaily`]: false,
          [`itemArr[${index}].showWeekly`]: false,
          [`itemArr[${index}].showMonthly`]: !this.data.itemArr[index].showMonthly,
          [`itemArr[${index}].dailyHeight`]: '0px',
          [`itemArr[${index}].weeklyHeight`]: '0px',
          [`itemArr[${index}].monthlyHeight`]: !this.data.itemArr[index].showMonthly ? rect.height + 'px' : 0 + 'px',
        });
        break;
      default:
        break;
    }
  },

  // 显示修改修改巡检周期窗口
  showUpdateFrequency(event) {
    let index = event.target.dataset.index;
    let item = event.target.dataset.item;
    let tag = event.target.dataset.tag;
    if (tag === "weekly") {
      //获取周的计划
      let weekobj = item.frequencyList[index[1]]
      let weekSelected = new Map()
      weekobj.dayValue.forEach(item=>{
        weekSelected.set(item,item)
      })
      this.setWeek(weekSelected);
      
      this.setData({
        showUpdateFrequencyOfWeek: true,
        freNum: weekobj.frequency,
        updateIndex:index,
        updateTag : tag
      });
    }

    if (tag === "monthly") {
      this.setDateNumber();
      this.setData({
        showUpdateFrequency: true,
        freNum: 1,
      });
    }
  },

  // 关闭修改月巡检周期窗口
  closeUpdateFrequency() {
    this.setData({
      showUpdateFrequency: false,
    });
  },

  // 关闭修改周巡检周期窗口
  closeUpdateFrequencyOfWeek() {
    this.setData({
      weeks: [],
      showUpdateFrequencyOfWeek: false,
    });
  },

  // 巡检日期填充（1号 ~ 31号）
  getFreDay(event) {
    let item = event.target.dataset.num
    let index = event.target.dataset.index

    this.setData({
      [`days[${index}].checked`]: !item.checked,
    });
  },

  // 巡检日期填充（周一 - 周日）
  getFreWeek(event) {
    let item = event.target.dataset.week
    let index = event.target.dataset.index

    this.setData({
      [`weeks[${index}].checked`]: !item.checked,
    });
  },

  // 确认修改月巡检周期
  confirmFre() {
    let numbers = []
    for (let i = 0; i < this.data.days.length; i++) {
      if (this.data.days[i].checked) {
        numbers.push(this.data.days[i])
      }
    }
    this.setData({
      days: []
    });

    this.setData({
      showUpdateFrequency: false,
      freNum: 1,
    });

    this.setDateNumber();
  },

  // 确认修改周巡检频次
  confirmFreWeek() {
    let numbers = []
    let dayValue = []
    let weekArr = []
    let dayShowName = []
    for (let i = 0; i < this.data.weeks.length; i++) {
      if (this.data.weeks[i].checked) {
        numbers.push(this.data.weeks[i]);
        dayValue.push(this.data.weeks[i].date)
        weekArr.push({
          id:this.data.weeks[i].date,
          name:this.data.weeks[i].week,
          checked:true
        })
        dayShowName.push(this.data.weeks[i].week);
      }
    }
    let editTag = this.data.updateTag;
    let editIndex = this.data.updateIndex;
    this.setData({
      [`itemArr[${editIndex[0]}].frequencyList[${editIndex[1]}].dayValue`]: dayValue,
      [`itemArr[${editIndex[0]}].frequencyList[${editIndex[1]}].weekArr`]: weekArr,
      [`itemArr[${editIndex[0]}].frequencyList[${editIndex[1]}].dayShowName`]: dayShowName
    })  
    this.closeUpdateFrequencyOfWeek();
  },

  // 显示任务窗口
  showTaskItem(event) {
    let obj = event.target.dataset.item.obj.taskObj
    let index = event.target.dataset.index
    let tag = event.target.dataset.tag
    let projectArr = event.target.dataset.item.obj.projectArr
    let projectNameArr = []
    projectArr.forEach(itemProject=>{
      projectNameArr.push(itemProject.name)
    })

    let task = {
      content: obj.taskRange,
      describe: obj.taskDescribe,
      require: obj.taskRequire,
      matter: obj.taskRange,
    }
    this.setData({
      showTaskItemWin: true,
      taskItem: task,
      taskItemIndex: index,
      projectNameArr:projectNameArr,
    });
  },

  // 关闭任务窗口
  closeTaskItem() {
    this.setData({
      showTaskItemWin: false,
      taskItem: '',
    });
  },

  // 修改任务
  updateTaskItem() {

    console.log("update task item...");

  },

  // 生成清单
  generateInspectionTaskList(event) {
    console.log("generate inspection task list...");
  },

  // 选择项目
  selectProject(event) {
    console.log("select project...");
    this.setData({
      showProjects: false
    });
  },

  // 关闭选择项目
  closeSelectProject() {
    this.setData({
      showProjects: false
    });
  },

  // 再项目列表中搜索项目
  searchProjectInList() {
    console.log("search project in list ...");
  },

  // 任务内容中修改项目 - 全选
  checkedAllProjectIntask(event) {
    this.setData({
      checkedAllProjectInTaskVal: !this.data.checkedAllProjectInTaskVal
    });
    
    if (!this.data.checkedAllProjectInTaskVal) {
      this.setData({
        checkedProjectInTaskVal: [],
      });
    }
  },

  // 任务内容中修改项目 - 挑选
  checkedProejctInTask(event) {
    this.setData({
      checkedProjectInTaskVal: event.detail,
      checkedAllProjectInTaskVal: this.data.checkedProjectInTaskVal.length === this.data.testProList.length
    });
    this.data.checkedAllProjectInTaskVal

  },

  // 保存任务关联项目
  confirmProjects() {
    console.log("confirm projects ...");
  },
})